package com.study.test.compare;

import java.util.Objects;

/**
 * @author 陈涛
 * @description:
 * @Date 2018/12/25 15:02
 */
public class Student implements  Comparable<Student>{
    private  String name;
    private Integer age1;
    private Integer age2;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge1() {
        return age1;
    }

    public void setAge1(Integer age1) {
        this.age1 = age1;
    }

    public Integer getAge2() {
        return age2;
    }

    public void setAge2(Integer age2) {
        this.age2 = age2;
    }

    @Override
    public int compareTo(Student o) {
        //return this.getAge1().compareTo(o.getAge1());
        return o.getAge1().compareTo(this.getAge1());
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age1=" + age1 +
                ", age2=" + age2 +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) &&
                Objects.equals(age1, student.age1) &&
                Objects.equals(age2, student.age2);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name, age1, age2);
    }
}
